package com.ghck.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.dao.DiseaseCategoryDictMapper;
import com.ghck.server.model.DiseaseCategoryDict;
import com.ghck.server.model.query.DiseaseCategoryDictQuery;
import com.ghck.server.service.DiseaseCategoryDictService;
import com.ghck.server.service.DiseaseService;

/**
 * 疾病分类  <br>
 * dict_disease_category <br>
 * v1.0 2016-05-01
 */
 @Service
 @Transactional
 public class DiseaseCategoryDictServiceImpl implements DiseaseCategoryDictService {
	
	private static final Logger logger = LoggerFactory.getLogger(DiseaseCategoryDictServiceImpl.class);
	
	@Autowired
	private DiseaseCategoryDictMapper diseaseCategoryDictMapper;
	@Autowired
	private DiseaseService diseaseService;
	
	/**
 	*根据ID删除 疾病分类
 	*/
 	@Override
 	public Integer deleteDiseaseCategoryDictById(Integer id){
 		return diseaseCategoryDictMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 疾病分类
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertDiseaseCategoryDict(List<? extends DiseaseCategoryDict> diseaseCategoryDicts){
		Integer count = diseaseCategoryDictMapper.batchInsert(diseaseCategoryDicts);
		return count;
 	}
 	/**
 	*新增 疾病分类
 	*/
 	@Override
 	@Transactional
 	public Integer insertDiseaseCategoryDict(DiseaseCategoryDict domain){
		Integer id = diseaseCategoryDictMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 疾病分类
 	*/
 	@Override
 	@Transactional
 	public Integer updateDiseaseCategoryDict(DiseaseCategoryDict domain){
		Integer count = diseaseCategoryDictMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 疾病分类
 	*/
 	public DiseaseCategoryDict findDiseaseCategoryDictById(Integer id){
 		DiseaseCategoryDict result = diseaseCategoryDictMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 疾病分类
 	*/
	public List<DiseaseCategoryDict> findDiseaseCategoryDictByQuery(DiseaseCategoryDictQuery query){
		query.dealWith();
		List<DiseaseCategoryDict> result = diseaseCategoryDictMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (DiseaseCategoryDict diseaseCategoryDict : result) {
				diseaseCategoryDict.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countDiseaseCategoryDictByQuery(DiseaseCategoryDictQuery query){
 		query.dealWith();
 		Integer result = diseaseCategoryDictMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<DiseaseCategoryDict> findDiseaseCategoryDictByIds(List<Integer> ids){
 		List<DiseaseCategoryDict> result = diseaseCategoryDictMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (DiseaseCategoryDict diseaseCategoryDict : result) {
				diseaseCategoryDict.dealWith();
			}
		}
		return result;
 	}
 	
 	/**
 	*根据name查询 身体部位
 	*/
	public DiseaseCategoryDict findByName(String name){
		DiseaseCategoryDict result = diseaseCategoryDictMapper.findByName(name);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
	}
	
	/**
 	*获取所有字典 身体部位
 	*/
	public List<DiseaseCategoryDict> findAll(){
		List<DiseaseCategoryDict> lsit = diseaseCategoryDictMapper.findAllByLevelOne();
		for(DiseaseCategoryDict dcd : lsit){
			dcd.setSubDiseaseCategoryDict(diseaseService.getDiseaseByCategoryId(dcd.getId()));
		}
		return lsit;
	}

	@Override
	public List<DiseaseCategoryDict> findAllByByParentId(Integer parentId) {
		
		return diseaseCategoryDictMapper.findAllByByParentId(parentId);
	}

	@Override
	public List<DiseaseCategoryDict> findAllByLevelOne() {
		// TODO Auto-generated method stub
		return diseaseCategoryDictMapper.findAllByLevelOne();
	}
	
	
}	